	<include file='Common:header' />

		<!-- /section:basics/navbar.layout -->
		<div class="main-container" id="main-container">

			<!-- #section:basics/sidebar -->

	<include file='Common:left' />


			<!-- /section:basics/sidebar -->
			<div class="main-content">
				<div class="main-content-inner">
					<div class="page-content">

                        
                        
                        <!--主题-->
						<div class="page-header">
							<h1>
								您当前操作
								<small>
									<i class="ace-icon fa fa-angle-double-right"></i>
									添加首页轮播图
								</small>
							</h1>
						</div>


						<div class="row">
							<div class="col-xs-12">
								<form class="form-horizontal" name="form0" id="form0"  method="post" action="{:U('add_banner_run')}"  enctype="multipart/form-data">
                                    <div class="form-group" id="pic_list">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> banner图片： </label>
										<div class="col-sm-9">
										<a href="javascript:;" class="file">
                                            <input type="file" name="file0" id="file0" multiple="multiple"/>
											选择上传文件
										</a>
										<a href="javascript:;" onclick="return backpic('__PUBLIC__/img/no_img.jpg');" title="还原修改前的图片" class="file">
                                            撤销上传
										</a>
										
										<div><img src="__PUBLIC__/img/no_img.jpg" width="320" height="180" id="img0" ></div>
										</div>
									</div>
                                    <div class="space-4"></div>

                                    <div class="form-group" id="pic_listurl">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 链接URL：  </label>
										<div class="col-sm-9">
											<input type="text" name="banner_url" id="plug_ad_url" placeholder="输入链接URL" class="col-xs-10 col-sm-8" />
											<span class="lbl">&nbsp;&nbsp;<span class="red">*</span>以http://开头，若不设置链接请填“#”</span>
										</div>
									</div>
                                    <div class="space-4"></div>

                                    <div class="form-group" id="pic_listurl">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序：  </label>
										<div class="col-sm-9">
											<input type="text" name="sort" id="sort" placeholder="排序从小到大，1.2.3..." class="col-xs-10 col-sm-8" />
											<span class="lbl">&nbsp;&nbsp;<span class="red">
										</div>
									</div>
                                    <div class="space-4"></div>
                                    
									<div class="clearfix form-actions">
										<div class="col-md-offset-3 col-md-9">
											<button class="btn btn-info" type="submit">
												<i class="ace-icon fa fa-check bigger-110"></i>
												保存
											</button>

											&nbsp; &nbsp; &nbsp;
											<button class="btn" type="reset">
												<i class="ace-icon fa fa-undo bigger-110"></i>
												重置
											</button>
										</div>
									</div>
								</form>
                        	</div>
                        </div>
									<div class="hr hr-24"></div>

<include file='Common:header_nav' />

					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->

	<include file='Common:footer' />

		</div><!-- /.main-container -->

	</body>
</html>
<script>
$(function(){
	$('#form0').ajaxForm({
		beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});
	
	function checkForm(){
		if( '' == $("#file0").val()){
			layer.alert('图片不能为空', {icon: 6}, function(index){
 			layer.close(index);
			$('#file0').focus(); 
			});
			return false;
		}
	
		if( '' == $.trim($('#plug_ad_url').val())){
			layer.alert('url不能为空，若不设置链接请填“#”', {icon: 6}, function(index){
 			layer.close(index);
			$('#plug_ad_url').focus(); 
			});
			return false;
		}
 }
	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}
	}
 
});

$("#file0").change(function(){
	var objUrl = getObjectURL(this.files[0]) ;
	console.log("objUrl = "+objUrl) ;
	if (objUrl) {
		$("#img0").attr("src", objUrl) ;
	}
}) ;

//建立一個可存取到該file的url
function getObjectURL(file) {

	var url = null ; 
	if (window.createObjectURL!=undefined) { // basic
		url = window.createObjectURL(file) ;
	} else if (window.URL!=undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file) ;
	} else if (window.webkitURL!=undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file) ;
	}
	return url ;
}


function backpic(picurl){
	$("#img0").attr("src",picurl);//还原修改前的图片
	$("input[name='file0']").val("");//清空文本框的值
}
$(document).ready(function(){
  $("#pic_jslist").hide();

  $("#plug_ad_checkjsid").click(function(){
  	$("#pic_jslist").show();
	$("#pic_list").hide();
	$("#pic_listurl").hide();
  });
  
  $("#plug_ad_checkid").click(function(){
  	$("#pic_jslist").hide();
	$("#pic_list").show();
	$("#pic_listurl").show();
  });
});

</script>
